<?php
error_reporting(0);
$isadmin=1; 
include_once '../../comm/config.php';
include_once '../include/page.class.php';
include_once '../../comm/checkpostandget.php';
include_once '../../comm/msgset.php';
if($_GET['action'] == 'allow'){
	$changeActiveSQL = "UPDATE ".$BIAOTOU."usershop SET `active`='1' WHERE`umiku_usershop`.`Id`=".$_GET['id'];
	mysql_query($changeActiveSQL);
}
if($_GET['action'] == 'deny'){
	$name = urldecode($_GET['username']);
	$sj = date("Y-m-d H:i:s");
	$msg_denyshop=str_replace("[why]",$_GET['denyReason'],$msg_denyshop);
	$insert = "INSERT into ".$BIAOTOU."msg(ddusername,title,content,addtime,senduser) values ('$name','拒绝店铺','".$msg_denyshop."','".$sj."','网站客服')";
	mysql_query($insert);
}
//查询级别
$sqlDefault="select * from ".$BIAOTOU."shoplevel";
$rs1 = mysql_query($sqlDefault);
//调用商铺类型
$shopTypeSql = "SELECT * FROM ".$BIAOTOU."shoptype ";
$shopTypeRes = mysql_query($shopTypeSql);
//
//调用行业信息
$sql="select * from ".$BIAOTOU."malltype";
$business_res = mysql_query($sql);
$verifying = (isset($_GET['link']))?"0":"";//申请中
$arr = array(
		'business'=> $_GET['business'],
		'province'=> $_GET['province'],
		'city'=>   	 $_GET['city'],
		'type'=>	 $_GET['type'],
		'name'=>	 trim($_GET['name']),
		'active'=>	 $verifying,
		'level' =>   $_GET['level']
		);
$usertype =  $_GET['usertype'];
$px=$_GET['px'];//排序
if($px=="")$px=2;
//查询总数
$sqlAccount="select * from ".$BIAOTOU."usershop";
$rs = mysql_query($sqlAccount);
$AllCount = mysql_num_rows($rs);
$sqlApplying = "select * from ".$BIAOTOU."usershop where `active` = 0";
$rs = mysql_query($sqlApplying);
$applyingCount = mysql_num_rows($rs);

$fxb=$_GET['fxb'];
if($fxb==1) $where_fxb=' and fxb=1';
else $where_fxb='';

$where="";
$page_url="manage.php?px=".$px;

foreach($arr as $k => $v){
	if(isset($v) && $v!=""){
		$page_url.="&{$k}=".urlencode($v);
		if(is_array($v)){
			foreach ($v as $kk=>$vv){
				$temp .= $vv."%";
			}
			$v = substr($temp,0,-1);
			$where .= "and ".$k ." LIKE '".$v."'";
		}else{
			if($k == 'name'){
				if($usertype == '0'){
					$k="username";
				}
				if($usertype == '1'){
					$k="ddshopname";
				}
			}
			$where .= "and ".$k ."='".$v."'";
		}
		
	}
}

if("" != $where){
	$where = substr_replace($where,'where',0,3);
}


//

$page = !($_GET['page'])?'1':intval($_GET['page']);
$pagesize=5;
$page2=($page-1)*$pagesize;
if($where!='') $where=$where.$where_fxb;

if($px=="1"){$where=$where." order by regtime  desc,id desc";}
if($px=="0"){$where=$where." order by regtime  asc,id desc";}
if($px=="2"){$where=$where." order by id desc";}
//用于查询
$sql="select * from ".$BIAOTOU."usershop $where";
$rs = mysql_query($sql);
$total = mysql_num_rows($rs)?mysql_num_rows($rs):0;	
//用于分页
$sql="select * from ".$BIAOTOU."usershop $where limit $page2,$pagesize";
$rs = mysql_query($sql);

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="../js/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>管理中心</title>
<link href="../css/style.css" rel="stylesheet" type="text/css"></head>

<body topmargin="5" leftmargin="0">
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="282" valign="top"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td>
          <table cellspacing="0" width="100%" height="207" style="border:1px  solid #DCEAF7;">
            <tr>
            <?php if($verifying == '0'){?>
              <td width="250" height="30" bgcolor="E9F2FB" class="bigtext"><a href="./manage.php">证实店铺</a>（<?php echo $AllCount; ?>）&nbsp;&nbsp;&nbsp;&nbsp;<strong><a href="./manage.php?link=verifying">申请中</a>（<?php echo $applyingCount; ?>）</strong></td>
            <?php }else{?>
              <td width="250" height="30" bgcolor="E9F2FB" class="bigtext"><strong><a href="./manage.php">证实店铺</a>（<?php echo $AllCount; ?>）</strong>&nbsp;&nbsp;&nbsp;&nbsp;<a href="./manage.php?link=verifying">申请中</a>（<?php echo $applyingCount; ?>）</td>
            <?php }?>  
              <form id="form1" name="form1" method="get" action="">
              <td width="580" height="30" bgcolor="E9F2FB" class="bigtext">
              <?php if($verifying != '0'){?>
              <label>
              	<select id="level" name="level">
              		<option value="">级别</option>
              		<?php 
              			while($level = mysql_fetch_array($rs1)){
              				if($_GET['level'] == $level['id']){
              					echo "<option selected value='{$level['id']}'>{$level['name']}</option>";
              				}else{
              					echo "<option value='{$level['id']}'>{$level['name']}</option>";
              				}
              		}
              		?>
              	</select>
              </label>
	          <?php }?>
              <label>
              	<select id="business" name="business">
			    <option value="">行业</option>
			    <?php 
				    while ($row = mysql_fetch_array($business_res)){
				    	if($_GET['business'] == $row["typename"]){
				    		$a1 = "<option value=".$row["typename"]." selected='selected'>".$row["typename"]."</option>";
				    	}else{
				    		$a1 = "<option value=".$row["typename"].">".$row["typename"]."</option>";
				    	}
				    	echo $a1;
				    }
			    ?>
			    </select>
              </label>
              <label>
             <select id="province" name="province" onchange="change_city(this.value);" >
		    <option value=""><?php if($verifying=='0'){?>全部省份<?php }else{?>地区<?php }?></option>
		    <option <?php echo $a2=($_GET['province'] == "北京")?"selected":"";?> value="北京">北京</option>
		    <option <?php echo $a2=($_GET['province'] == "上海")?"selected":"";?> value="上海">上海</option>
		    <option <?php echo $a2=($_GET['province'] == "天津")?"selected":"";?> value="天津">天津</option>
		    <option <?php echo $a2=($_GET['province'] == "重庆")?"selected":"";?> value="重庆">重庆</option>
		    <option <?php echo $a2=($_GET['province'] == "河北")?"selected":"";?> value="河北">河北</option>
		    
		    <option <?php echo $a2=($_GET['province'] == "山西")?"selected":"";?>  value="山西">山西</option>
		    <option <?php echo $a2=($_GET['province'] == "内蒙古")?"selected":"";?>  value="内蒙古">内蒙古</option>
		    <option <?php echo $a2=($_GET['province'] == "辽宁")?"selected":"";?> value="辽宁">辽宁</option>
		    <option <?php echo $a2=($_GET['province'] == "吉林")?"selected":"";?>  value="吉林">吉林</option>
		    <option <?php echo $a2=($_GET['province'] == "黑龙江")?"selected":"";?> value="黑龙江">黑龙江</option>
		    
		    <option <?php echo $a2=($_GET['province'] == "江苏")?"selected":"";?>  value="江苏">江苏</option>
		    <option <?php echo $a2=($_GET['province'] == "浙江")?"selected":"";?>  value="浙江">浙江</option>
		    <option <?php echo $a2=($_GET['province'] == "安徽")?"selected":"";?>  value="安徽">安徽</option>
		    <option <?php echo $a2=($_GET['province'] == "福建")?"selected":"";?>  value="福建">福建</option>
		    <option <?php echo $a2=($_GET['province'] == "江西")?"selected":"";?>  value="江西">江西</option>
		    
		    <option <?php echo $a2=($_GET['province'] == "山冻")?"selected":"";?>  value="山冻">山东</option>
		    <option <?php echo $a2=($_GET['province'] == "河南")?"selected":"";?>  value="河南">河南</option>
		    <option <?php echo $a2=($_GET['province'] == "湖北")?"selected":"";?>  value="湖北">湖北</option>
		    <option <?php echo $a2=($_GET['province'] == "广东")?"selected":"";?>  value="广东">广东</option>
		    <option <?php echo $a2=($_GET['province'] == "四川")?"selected":"";?>  value="四川">四川</option>
		    
		    <option <?php echo $a2=($_GET['province'] == "贵州")?"selected":"";?> value="贵州">贵州</option>
		    <option <?php echo $a2=($_GET['province'] == "云南")?"selected":"";?> value="云南">云南</option>
		    <option <?php echo $a2=($_GET['province'] == "西藏")?"selected":"";?> value="西藏">西藏</option>
		    <option <?php echo $a2=($_GET['province'] == "陕西")?"selected":"";?> value="陕西">陕西</option>
		    <option <?php echo $a2=($_GET['province'] == "甘肃")?"selected":"";?> value="甘肃">甘肃</option>
		    
		    <option <?php echo $a2=($_GET['province'] == "宁夏")?"selected":"";?>  value="宁夏">宁夏</option>
		    <option <?php echo $a2=($_GET['province'] == "青海")?"selected":"";?>  value="青海">青海</option>
		    <option <?php echo $a2=($_GET['province'] == "新疆")?"selected":"";?>  value="新疆">新疆</option>
		    </select>
              </label>
                <label>
                <?php if($verifying == '0'){?>
	                <select id="city" name="city">
				    <option value="">全部城市</option>
				    <?php echo $a3 = (isset($_GET['city']))?"<option selected value='".$_GET['city']."'>".$_GET['city']."</option>":"";?>
			    </select>
	            <?php }?>
			    <?php 
			    	$gametype=$_GET['type'];
			    	while($type = mysql_fetch_array($shopTypeRes)){
		    		if(in_array($type['id'],$gametype)){
		    			echo "<input checked name='type[]' type='checkbox' value='{$type['id']}' class='FLeft check' align='middle'><span class='FLeft'>{$type['typename']}</span>";
		    		}else{
		    			echo "<input name='type[]' type='checkbox' value='{$type['id']}' class='FLeft check' align='middle'><span class='FLeft'>{$type['typename']}</span>";
		    			}
		    			 
		    			}
			    ?>
                </label>
                <label>
                <select id="usertype" name="usertype">
			    <option <?php echo $a5=($_GET['usertype']=='0')?"selected":"";?> value="0">用户名</option>
			    <option <?php echo $a5=($_GET['usertype']=='1')?"selected":"";?> value="1">店名</option>
			    </select>
               <input type="text" style="width:80px" name="name" value="<?php echo $a6=($_GET['name'])?trim($_GET['name']):"";?>" />
                </label>
                 <?php if($verifying == '0'){?>
             		<input type="hidden"  name="link" value="0"/>
	             <?php }?>
                            <label>
                            <input type="submit" name="Submit" value="查找" />
                            </label>
              </td> </form>
              <td width="150" align="right" bgcolor="E9F2FB" class="bigtext">共有 <b><?php echo $total;?></b> 条记录&nbsp;&nbsp;</td>
            </tr>
            <tr>
              <td colspan="3" valign="top"><table width="100%" height="300" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td valign="top"><table width="100%" border=1 cellpadding=0 cellspacing=0
style="border-collapse: collapse" bordercolor="#dddddd">
                  
                    <tr>
                      <td width="4%" height="30" align="center" bgcolor="#F2F2F2" class="bigtext"><strong>&nbsp;ID</strong></td>
                      <td width="" height="30" align="center" bgcolor="#F2F2F2" class="bigtext"><strong>&nbsp;店名/用户名</strong></td>
                      <td width="20%" align="center" bgcolor="#F2F2F2" class="bigtext"><strong>手机号/网店地址</strong></td>
                      <?php if($verifying == '0'){?>
						<td width="11%" align="center" bgcolor="#F2F2F2" class="bigtext"><strong>&nbsp;姓名</strong></td>
					  <?php }else{?>
						<td width="11%" align="center" bgcolor="#F2F2F2" class="bigtext"><strong>&nbsp;级别</strong></td>
			          <?php }?>
                      <td width="13%" align="center" bgcolor="#F2F2F2" class="bigtext"><strong>&nbsp;行业|店铺类型</strong></td>
                      <td width="11%" align="center" bgcolor="#F2F2F2" class="bigtext"><strong>&nbsp;地区</strong></td>
                      <td width="7%" align="center" bgcolor="#F2F2F2" class="bigtext"><strong>&nbsp;申请时间 <?php if($px=="0"){echo "<a href=\"manage.php?px=1\"><img src='../images/up.gif' title='向上排序'/></a>";}elseif($px=="1"){echo "<a href=\"manage.php?px=0\"><img src='../images/drop.gif' title='向下排序'/></a>";}else{echo "<a href=\"manage.php?px=0\"><img src='../images/nochoice.gif' title='未选中'/></a>";}?></strong></td>
                      <td width="7%" align="center" bgcolor="#F2F2F2" class="bigtext"><strong>&nbsp;备注</strong></td>
                      <td width="12%" align="center" bgcolor="#F2F2F2" class="bigtext"><strong>&nbsp;执行操作</strong></td>
                    </tr>
					<?php
					$i = 1;
					while ($row = mysql_fetch_array($rs))
					{
						echo "<tr>";
                      	echo "<td align=center height=30 class=bigtext>&nbsp;".$i."</td>";
                      	echo "<td align=center height=30 class=bigtext>&nbsp;".$row["ddshopname"]."|<br>".$row["username"]."</td>";
                      	echo "<td align=center height=30 class=bigtext>&nbsp;".$row["contact_mobile"]."|<br>".$row["url"]."</td>";
						if($verifying == '0'){
							echo "<td align=center class=bigtext>&nbsp;".$row["contact_username"]."</td>";
						}else{
							if($row['level'] == 1){
								echo "<td align=center class=bigtext>&nbsp;一级</td>";
							}else{
								echo "<td align=center class=bigtext>&nbsp;二级</td>";
							}
							
						}
						switch($row["type"]){
							case "1":
								$shoptype = "实体店";
								break;
							case "12":
								$shoptype = "实体店-网站";
								break;
							case "13":
								$shoptype = "实体店-厂家";
								break;
							case "2":
								$shoptype = "网站";
								break;
							case "23":
								$shoptype = "网站-厂家";
								break;
							case "3":
								$shoptype = "厂家";
								break;
							case "123":
								$shoptype = "实体店-网站-厂家";
								break;
						}
						echo "<td align=center class=bigtext>&nbsp;".$row["business"]."|<br>".$shoptype."</td>";
						echo "<td align=center class=bigtext>&nbsp;".$row["province"]."-".$row["city"]."</td>";
						echo "<td align=center class=bigtext>&nbsp;".$row["regtime"]."</td>";
						echo "<td align=center class=bigtext>&nbsp;".$row["comment"]."</td>";
						if($verifying == '0'){
							echo "<td align=center align=center class=bigtext><a onclick=allowConfirm('".$row["ddshopname"]."','".$row["Id"]."'); href=javascript:void(0); class=link4>通过</a> <a onclick=denyConfirm('".$row["ddshopname"]."','".urlencode($row["username"])."'); href=javascript:void(0); class=link4>拒绝</a></td>";
						}else{
							echo "<td align=center align=center class=bigtext><a href=mingxi.php?id=".$row["Id"]." class=link4>明细</a> <a href=xiangxi.php?id=".$row["Id"]." class=link4>详细</a> <a href=delete.php?id=".$row["Id"]." class=link4>删除</a></td>";
						}
						
						echo "</tr>";
						$i ++;
					}
					?></table>
					<div class="yahoo2" style=" margin-top:30px;"><?php 
				pageft($total,$pagesize,1,1,0,10,$page_url);
				echo $pagenav;?></div>
					</td>
                </tr>
              </table></td>
            </tr>
          </table></td>
        </tr>
      
    </table></td>
  </tr>
</table>
<script>
function change_city(province){
	$("#city").html("<option value=''>请选择市</option>");
    switch (province) {
		case "北京" :var cityOptions = new Array("北京");
			break;	
		case "上海" :var cityOptions = new Array("上海");
			break;	
		case "天津" :var cityOptions = new Array("天津");
			break;	
		case "重庆" :var cityOptions = new Array("重庆");
			break;	
		case "河北" :
			var cityOptions = new Array("石家庄","张家口","承德","唐山","廊坊","保定","沧州","衡水","邢台","邯郸");	break;	
		case "山西" :
			var cityOptions = new Array("太原","大同","朔州","阳泉","长治","晋城","忻州","离石","榆次","临汾","运城");	break;	
		case "内蒙古" :
			var cityOptions = new Array("呼和浩特","包头","乌海","赤峰","海拉尔","乌兰浩特","通辽","锡林浩特","集宁","东胜","临河","阿拉善左旗","鄂尔多斯");	break;			
		case "辽宁" :
			var cityOptions = new Array("沈阳","朝阳","阜新","铁岭","抚顺","本溪","辽阳","鞍山","丹东","大连","营口","盘锦","锦州","葫芦岛");
			 break;  
		case "吉林" :
			var cityOptions = new Array("长春","白城","松原","吉林","四平","辽源","通化","白山","延吉");		
		case "黑龙江" :
			var cityOptions = new Array("哈尔滨","齐齐哈尔","黑河","大庆","伊春","鹤岗","佳木斯","双鸭山","七台河","鸡西","牡丹江","绥化","加格达奇");break;	
		case "江苏" :
			var cityOptions = new Array("南京","苏州","徐州","连云港","宿迁","淮安","盐城","扬州","泰州","镇江","常州","无锡");
			break;	
		case "浙江" :
			var cityOptions = new Array("杭州","湖州","嘉兴","舟山","宁波","绍兴","金华","台州","温州","丽水","衢州");
			break;	
		case "安徽" :
			var cityOptions = new Array(
			"合肥", "宿州", "淮北", "阜阳", "蚌埠", "淮南", "滁州", "马鞍山", "芜湖", "铜陵", "安庆", "黄山", "六安", "巢湖", "贵池", "宣城", "亳州");			break;	
		case "福建" :
			var cityOptions = new Array("福州", "南平", "三明", "莆田", "泉州", "厦门", "漳州", "龙岩", "宁德", "福安", "邵武", "石狮", "永安", "武夷山", "福清");	
			break;	
		case "江西" :
			var cityOptions = new Array("南昌", "九江", "景德镇", "鹰潭", "新余", "萍乡", "赣州", "上饶", "临川", "宜春", "吉安", "抚州");
			break;	
		case "山东" :
			var cityOptions = new Array("聊城", "德州", "东营", "淄博", "潍坊", "烟台", "威海", "青岛", "日照", "临沂", "枣庄", "济宁", "泰安", "莱芜", "滨州", "菏泽");
			break;					
		case "河南" :
			var cityOptions = new Array("郑州", "三门峡", "洛阳", "焦作", "新乡", "鹤壁", "安阳", "濮阳", "开封", "商丘", "许昌", "漯河", "平顶山", "南阳", "信阳", "济源", "周口", "驻马店");	
			break;					
		case "湖北" :
			var cityOptions = new Array("武汉", "十堰",  "襄樊", "荆门",  "孝感",  "黄冈", "鄂州",  "黄石", "咸宁", "荆州", "宜昌",  "恩施", "仙桃", "潜江",  "随州", "广水", "天门");
			break;				
		case "湖南" :
			var cityOptions = new Array("长沙", "张家界", "常德", "益阳", "岳阳", "株洲", "湘潭", "衡阳", "郴州",  "永州", "邵阳", "怀化", "娄底", "吉首" );break;
		case "广东" :
			var cityOptions = new Array("广州", "深圳",  "清远", "韶关", "河源",  "梅州",  "潮州",  "汕头", "揭阳", "汕尾",  "惠州", "东莞",  "珠海", "中山",  "江门", "佛山",  "茂名",  "湛江",  "阳江", "云浮",  "肇庆");
			break;
		case "广西" :
			var cityOptions = new Array("南宁", "桂林", "柳州",  "贺州", "玉林", "钦州", "北海", "防城港", "百色", "河池", "贵港", "梧州");
			break;			
		case "海南" :
			var cityOptions = new Array("海口",  "三亚", "儋州");
			break;				
		case "四川" :
			var cityOptions = new Array("成都", "广元", "绵阳", "德阳", "南充", "广安", "遂宁",  "内江", "乐山", "自贡", "泸州", "宜宾", "攀枝花", "巴中", "达州", "资阳", "雅安", "西昌", "眉山", "泸定");
			break;				
		case "贵州" :
			var cityOptions = new Array("贵阳", "六盘水", "遵义", "毕节", "铜仁", "安顺", "凯里", "都匀", "兴义");
			break;			
		case "云南" :
			var cityOptions = new Array("昆明", "曲靖", "玉溪", "丽江",  "昭通", "思茅", "临沧", "保山", "潞西", "泸水", "中甸", "大理", "楚雄", "个旧", "文山", "景洪", "红河");
			break;				
		case "西藏" :
			var cityOptions = new Array( "拉萨", "那曲", "昌都",  "林芝", "乃东", "日喀则", "噶尔");
			break;				
		case "陕西" :
			var cityOptions = new Array( "西安", "延安", "铜川",  "渭南", "咸阳", "宝鸡", "汉中",  "榆林", "商洛", "安康");
			break;				
		case "甘肃" :
			var cityOptions = new Array( "兰州", "嘉峪关", "白银", "天水",  "酒泉", "张掖",  "金昌", "庆阳", "平凉", "定西", "陇南", "临夏", "武威");
			break;			
		case "宁夏" :
			var cityOptions = new Array( "银川",  "石嘴山", "吴忠", "固原");
			break;				
		case "青海" :
			var cityOptions = new Array( "西宁", "平安", "海晏",  "共和", "同仁", "玛沁", "玉树", "德令哈");
			break;		
		case "新疆" :
			var cityOptions = new Array( "乌鲁木齐", "克拉玛依", "石河子",  "喀什",   "阿克苏",  "和田",  "吐鲁番", "哈密", "阿图什", "博乐", "昌吉", "库尔勒",  "伊犁", "奎屯", "塔城",  "阿勒泰");
			break;	
		default:
			var cityOptions = new Array("北京");
			break;
	} 
	for(var i = 0; i < cityOptions.length; i++){
		var option = "<option value='"+cityOptions[i]+"'>"+cityOptions[i]+"</option>";  
		$("#city").append(option);  
	} 
}  

function allowConfirm(shopname,id){
	 if(confirm("通过'"+shopname+"'的店铺申请？")){
		 alert("已经通过'"+shopname+"'的店铺申请");
		 location.href="./manage.php?link=verfying&action=allow&id="+id;
	 }else{
		 return false;
	 }
	    
}

function denyConfirm(shopname,username){
	if(confirm("拒绝'"+shopname+"'的店铺申请？")){
		var reason=prompt("拒绝'"+shopname+"'的店铺申请，请输入拒绝理由：","")
		 alert("已经拒绝'"+shopname+"'的店铺申请");
		 location.href="./manage.php?link=verfying&action=deny&username="+username+"&denyReason="+reason;
	 }else{
		 return false;
	 }
}
</script>
</body>
</html>
<?php mysql_close($link);?>
